package cc.lj.internal.api.coupons.api.ticket.fallbackfactory;

import cc.lj.internal.api.coupons.api.ticket.TicketPayRecordFeignService;
import cc.lj.internal.api.coupons.dto.TicketPayRecordApiDTO;
import cc.lj.internal.api.coupons.dto.command.TicketPayRecordApiUpdateCommand;
import cc.lj.internal.api.coupons.dto.querty.TicketPayRecordApiQuery;
import cc.lj.internal.core.http.HttpResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 合同收券表fegin回退处理，可以打印出具体回退原因
 * 注意：只有配置文件中开启hystrix (feign.hystrix.enabled=true),该配置才会起作用
 * @author liangxifeng
 * @date 2022-01-12
 */
@Slf4j
@Component
public class TicketPayRecordFeignServiceFallbackFactory implements FallbackFactory<TicketPayRecordFeignService> {
    @Override
    public TicketPayRecordFeignService create(Throwable throwable) {
        return new TicketPayRecordFeignService() {
            /**
             * 等值查询列表
             * @param ticketPayRecordApiQuery
             * @return 合同收券list
             */
            @Override
            public HttpResult<List<TicketPayRecordApiDTO>> getList(TicketPayRecordApiQuery ticketPayRecordApiQuery) {
                log.error("feign--请求合同收券表查询getList接口失败,原因:" + throwable.getMessage());
                return new HttpResult<>(HttpResult.SERVICE_FUSING.getCode(), HttpResult.SERVICE_FUSING.getMessage());
            }

            @Override
            public HttpResult<Integer> updateById(TicketPayRecordApiUpdateCommand ticketPayRecordApiUpdateCommand) {
                log.error("feign--请求合同收券表查询通过主键修改数据接口失败,原因:" + throwable.getMessage());
                return new HttpResult<>(HttpResult.SERVICE_FUSING.getCode(), HttpResult.SERVICE_FUSING.getMessage());
            }
        };
    }
}
